<?php
namespace app\admin\controller;
use app\admin\model\MessageModel;
use  app\admin\model\Honor;
use think\Controller;
use think\Db;

class Index extends Common
{
    public function index()
    {
        $userNear = $this->userNear();              //每天浏览人数
        $this->assign('userNear', $userNear);

        $personnelMessage = $this->personnelMessage();//人事通知信息
        $this->assign('personnelMessage', $personnelMessage);
        $Honor = $this->Honor();//每月优秀员工
        foreach ($Honor as $k=>$v){
            $arr = explode(',',$v['label_id']);
            foreach ($arr as $m=>$n){
                $arr[$m] = Db::name('label')->field('id,title')->where(['id'=>$n])->find();
            }
            $Honor[$k]['labelArr'] =$arr;
        }
        $this->assign('honor', $Honor);
        return $this->fetch();
    }

    /**
     * 人事信息通知
     */
    private  function personnelMessage()
    {
        return $MessageList = Db::name('message')->ORDER('id','desc')->find();
    }
    /**
     * 每月优秀员工
     */
    private  function Honor()
    {
        return $honorList=Db::query("select h.*,u.name as user_name,uf.avatar,am.name as am_name from tf_honor as h 
                                     left join tf_user as u on h.user_id=u.id 
                                     left join tf_user_info as uf on h.user_id=uf.uid
                                     left join tf_arctype_mod as am on u.mod_id=am.id 
                                     where date_format(h.operation_time,'%Y-%m')=date_format(now(),'%Y-%m') 
                                     order by operation_time desc");
    }
    /**
     * @Title: userNear
     * @Description: todo(最近7天注册用户)
     * @author zyy
     * @date 2018年11月14日
     * @throws
     */
    private function userNear()
    {
        $userModel = new \app\admin\model\User;
        $nowTime = strtotime(date('Ymd', time())) + 86400;
        $userTime = $nowTime - 604800;
        return $userNear = $userModel->where('last_time', 'egt', $userTime)->count();
    }

    
    /**
     * @Title: cleanCache
     * @Description: todo(清除缓存)
     * @author zyy
     * @date 2018年11月14日
     * @throws
     */
    public function cleanCache()
    {
        if (request()->isPost()){
            deldir(RUNTIME_PATH);
            return ajaxReturn(lang('action_success'));
        }else{
            deldir(RUNTIME_PATH);
            return $this->fetch();
        }
    }
    
    
    
    
    public function icons()
    {
        return $this->fetch();
    }
    
    public function forms()
    {
        return $this->fetch();
    }
    
    public function box()
    {
        return $this->fetch();
    }
    
    public function tab()
    {
        return $this->fetch();
    }
    
    public function tables()
    {
        return $this->fetch();
    }
    
    public function question()
    {
        return $this->fetch();
    }
}
